import 'package:catguard/language.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../config/config.dart';
import '../../generated/assets.dart';
import '../../routers/routers.dart';
import '../../utils/count_down_time_util.dart';
import '../../utils/edit_focus_util.dart';
import '../../views/common_widget.dart';
import 'login_logic.dart';

class LoginPage extends StatelessWidget {
  LoginPage({super.key});

  final logic = Get.find<LoginLogic>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      backgroundColor: Config.colorBg2,
      body: InkWell(
        splashColor: Colors.transparent,
        highlightColor: Colors.transparent,
        onTap: () {
          FocusManager.instance.primaryFocus?.unfocus();
        },
        child: Stack(
          children: [
            Column(
              children: [
                //appbar
                CommonWidget.commonAppBar(''),
                //logo
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Container(
                        margin: EdgeInsets.only(top: 15.w),
                        width: 200.w,
                        height: 200.w,
                        padding: EdgeInsets.all(2.w),
                        decoration: BoxDecoration(
                          color: Config.colorBg2.withOpacity(0.6),
                          borderRadius: BorderRadius.circular(50.w),
                        ),
                        child: ClipRRect(
                          borderRadius: BorderRadius.circular(50.w),
                          child: Image.asset(
                            Assets.imagesLauncher,
                          ),
                        )),
                  ],
                ),
                //提示语
                Container(
                    margin: EdgeInsets.only(top: 15.w),
                    padding: EdgeInsets.symmetric(horizontal: 60.w),
                    child: Column(
                      children: [
                        Text(
                          LanguageMsg.loginTips.tr,
                          textAlign: TextAlign.center,
                          style: TextStyle(
                              color: Config.colorText1,
                              fontSize: Config.textSizeSubTitle.sp,
                              height: 1.6),
                        ),
                      ],
                    )),
                //中间
                Container(
                  padding: EdgeInsets.only(top: 20.w, left: 60.w, right: 60.w, bottom: 20.w),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      //输入框1
                      Container(
                        margin: EdgeInsets.only(top: 40.w, bottom: 24.w),
                        alignment: Alignment.centerLeft,
                        child: Text(
                          LanguageMsg.userName.tr,
                          style: TextStyle(
                            color: Config.colorText1,
                            fontSize: Config.textSizeSubTitle.sp,
                          ),
                        ),
                      ),
                      CommonWidget.commonEditText(
                        false,
                        (value) {
                          //获得输入的内容
                          logic.userName.value = value;
                        },
                        () {
                          //输入框被点击了
                          EditFocusUtils.setFocus(logic.focusNode1);
                        },
                        () {
                          //右边图标被点击了
                        },
                        logic.focusNode1,
                        isRightIcon: false,
                        maxLength: 40,
                        contentPaddingV: 25.w,
                        hint: "login_input_email_tips".tr,
                        fillColor: Config.colorBg.withOpacity(0.88),
                        sideColorN: Config.colorText2.withOpacity(0.04),
                        sideColorP: Config.colorText1,
                        keyboardType: TextInputType.text,
                        fontSize: Config.textSizeContent.sp,
                      ),
                      Container(
                        margin: EdgeInsets.only(top: 40.w, bottom: 24.w),
                        alignment: Alignment.centerLeft,
                        child: Text(
                          LanguageMsg.loginTagPwd.tr,
                          style: TextStyle(
                            color: Config.colorText1,
                            fontSize: Config.textSizeSubTitle.sp,
                          ),
                        ),
                      ),
                      //输入框2
                      Obx(
                        () => CommonWidget.commonEditText(
                          logic.isHidePwd.value,
                          (value) {
                            //获得输入的内容
                            logic.passWord.value = value;
                          },
                          () {
                            //输入框被点击了
                            EditFocusUtils.setFocus(logic.focusNode2);
                          },
                          () {
                            //右边图标被点击了
                            logic.isHidePwd.value = !logic.isHidePwd.value;
                          },
                          logic.focusNode2,
                          isRightIcon: true,
                          contentPaddingV: 25.w,
                          rightIconRight: 25.w,
                          maxLength: 20,
                          hint: "login_input_pwd_tips".tr,
                          fillColor: Config.colorBg.withOpacity(0.88),
                          sideColorN: Config.colorText3.withOpacity(0.04),
                          sideColorP: Config.colorText1,
                          keyboardType: TextInputType.text,
                          fontSize: Config.textSizeContent.sp,
                        ),
                      ),
                      SizedBox(height: 50.w),
                      //登录按钮
                      GestureDetector(
                        onTap: () {
                          logic.login();
                        },
                        child: Container(
                          margin: EdgeInsets.fromLTRB(0.w, 30.w, 0.w, 0.w),
                          padding: EdgeInsets.symmetric(horizontal: 22.w),
                          height: 96.w,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.all(Radius.circular(58.w)),
                            border: Border.all(color: Config.colorText1,width: 3.w),
                            gradient: LinearGradient(
                              begin: Alignment.topCenter,
                              end: Alignment.bottomCenter,
                              colors: [Config.colorMain, Config.colorMain.withOpacity(0.9)],
                            ),
                          ),
                          child: Text(
                            "login_btn".tr,
                            style: TextStyle(color: Config.colorText1, fontSize: 34.sp),
                          ),
                        ),
                      ),
                      //忘记密码和注册
                      Container(
                        margin: EdgeInsets.only(right: 50.w, top: 30.w, left: 50.w),
                        width: double.infinity,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            InkWell(
                              splashColor: Colors.transparent,
                              highlightColor: Colors.transparent,
                              onTap: () {
                                // Get.toNamed(Routes.forgetPassword, arguments: {'isChange': false});
                              },
                              child: Container(
                                alignment: Alignment.center,
                                margin: EdgeInsets.only(top: 0.w, left: 70.w),
                                child: Text(
                                  LanguageMsg.registerBottomLogin2.tr,
                                  style: TextStyle(
                                      color: Config.colorText1,
                                      fontSize: Config.textSizeContent.sp),
                                ),
                              ),
                            ),
                            Container(
                              margin: EdgeInsets.symmetric(horizontal: 15.w),
                              width: 3.w,
                              height: 26.w,
                              decoration: const BoxDecoration(color: Config.colorDivider),
                            ),
                            InkWell(
                              splashColor: Colors.transparent,
                              highlightColor: Colors.transparent,
                              onTap: () {
                                Get.toNamed(Routes.register);
                              },
                              child: Container(
                                alignment: Alignment.center,
                                margin: EdgeInsets.only(top: 0.w, right: 70.w),
                                child: Text(
                                  LanguageMsg.loginNewRegister.tr,
                                  style: TextStyle(
                                      color: Config.colorMain, fontSize: Config.textSizeContent.sp),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
